package com.liu.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liu.reggie.common.CustomerException;
import com.liu.reggie.mapper.DishMapper;
import com.liu.reggie.mapper.SetmealMapper;
import com.liu.reggie.pojo.Category;
import com.liu.reggie.pojo.Dish;
import com.liu.reggie.pojo.Setmeal;
import com.liu.reggie.service.CategoryService;
import com.liu.reggie.mapper.CategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category>
    implements CategoryService{

    @Autowired
    DishMapper dishMapper;

    @Autowired
    SetmealMapper setmealMapper;

    @Override
    public void remove(Long id) {
        LambdaQueryWrapper<Dish> dishLambdaQueryWrapper = new LambdaQueryWrapper<>();
        dishLambdaQueryWrapper.eq(Dish::getCategoryId,id);
        Integer count = dishMapper.selectCount(dishLambdaQueryWrapper);
        if (count>0){
            throw new CustomerException("含有菜品不能删除");
        }
        LambdaQueryWrapper<Setmeal> setmealLambdaQueryWrapper = new LambdaQueryWrapper<>();
        setmealLambdaQueryWrapper.eq(Setmeal::getCategoryId,id);
        Integer count1 = setmealMapper.selectCount(setmealLambdaQueryWrapper);
        if (count1>0){
            throw new CustomerException("含有套餐 不能删除");
        }
        super.removeById(id);
    }
}




